using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Mpi.Common.Controls
{
    public partial class BusyDialog : Form
    {

        private bool _allowCancel;

        public bool AllowCancel
        {
            get { return buttonCancel.Visible; }
            set { buttonCancel.Visible = value; }
        }

        public string Message
        {
            get { return label1.Text; }
            set { label1.Text = value; }
        }


        private bool _busy = false;
        public void ShowBusy(Form mainForm, string message)
        {
            if (!_busy)
            {
                _busy = true;
                this.busyCtrl1.Busy = true;
                this.Visible = true;
                this.TopMost = true;
                this.MaximumSize = mainForm.Size;

                this.Size = mainForm.Size;
                this.DesktopLocation = mainForm.DesktopLocation;
            }
            this.Message = message + "\r\nPlease wait...";
        }

        public void HideBusy()
        {
           
            this.Visible = false;
            this.busyCtrl1.Busy = false;
            _busy = false;
        }


        public BusyDialog()
        {
            InitializeComponent();

            // this.Shown += new EventHandler(BusyDialog_Shown);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            if(Cancel != null)
                Cancel(this, new EventArgs());
        }


        public event EventHandler Cancel;

        //void BusyDialog_Shown(object sender, EventArgs e)
        //{
        //    if (this.Owner != null)
        //    {
        //        this.Left = this.Owner.Left;
        //        this.Top = this.Owner.Top;
        //        this.Width = this.Owner.Width;
        //        this.Height = this.Owner.Height;
        //    }
        //}


    }
}